package com.wandian.setting.mvvm.modifynicename;

import androidx.databinding.DataBindingUtil;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.mylib.libcore.config.RouterConfig;
import com.mylib.libcore.mvvm.BaseMVVMActivity;
import com.mylib.libcore.utils.ToastUtil;
import com.mylib.libcore.utils.UIUtils;
import com.mylib.widget.SelectPopupWindow;
import com.wandian.setting.R;
import com.wandian.setting.databinding.SetActivityModifyNiceNameBinding;

/**
 * @author Administrator
 * @date 2019/12/18-14:28
 * @description  修改用户昵称
 **/
@Route(path = RouterConfig.ROUTER_ACTIVITY_SETTING_MODIFY_USER_NAME)
public class ModifyNiceNameActivity extends  BaseMVVMActivity<ModifyNiceNameViewModel>  {
    private SetActivityModifyNiceNameBinding dataBinding;

    @Override
    public void init(Bundle savedInstanceState) {
        dataBinding = DataBindingUtil.setContentView(this, R.layout.set_activity_modify_nice_name);
        dataBinding.setLifecycleOwner(this);
        dataBinding.setViewModel(mViewModel);
        dataBinding.bindToolBar.toolBarTvTitle.setText("昵称");
        initClink();
    }

    private void initClink(){
        dataBinding.bindToolBar.toolBarTitleLeft.setOnClickListener(v -> {
            finishhideSoftBoard();
            finish();
        });
        dataBinding.bindToolBar.toolBarTitleRight.setTextColor(getResources().getColor(R.color.sys_text_color));

        dataBinding.etNiceName.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                if(!UIUtils.isEmpty(s)){
                    dataBinding.tvNumber.setText(s.toString().trim().length()+"");
                }else {
                    dataBinding.tvNumber.setText("0");
                }
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });

        dataBinding.bindToolBar.toolBarTitleRight.setOnClickListener(v -> {
            finishhideSoftBoard();
            if(UIUtils.isEmpty(dataBinding.etNiceName.getText()) || dataBinding.etNiceName.getText().toString().trim().length()<2){
                ToastUtil.show("请输入2-10个字符昵称");
                return;
            }
            mViewModel.modifyName(dataBinding.etNiceName.getText().toString().trim());

        });

    }

}
